package com.xiaobaibai.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.xiaobaibai.handler.ListTypeHandler;
import com.xiaobaibai.valid.AddGroup;
import com.xiaobaibai.valid.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author xiaobaibai
 * @since 2020-10-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("product")
@ApiModel(value="Product对象", description="")
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Product implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private Boolean hotProduct;

    @TableField(exist = false)
    private Boolean newProduct;

    @ApiModelProperty(value = "商品图片")
    @TableField(value = "product_image",typeHandler = ListTypeHandler.class)
    @NotNull(message = "商品图片不可为空",groups = AddGroup.class)
//    @TableField(exist = false)
    private List<String> productImage;

//    @ApiModelProperty(value = "商品图片")
//    @TableField("product_image")
//    @NotNull(message = "商品图片不可为空",groups = AddGroup.class)
//    private String productImage;

    @ApiModelProperty(value = "商品id")
    @TableId(value = "id", type = IdType.AUTO)
    @Null(message = "新增不可指定id",groups = AddGroup.class)
    @NotNull(message = "修改需指定id",groups = UpdateGroup.class)
    private Integer id;

    @ApiModelProperty(value = "分类id")
    @TableField("category_id")
    @NotNull(message = "分类id不可为空",groups = AddGroup.class)
    private Integer categoryId;

    @ApiModelProperty(value = "商品名称")
    @TableField("product_name")
    @NotNull(message = "商品名称不可为空",groups = AddGroup.class)
    private String productName;

    @ApiModelProperty(value = "销量")
    @TableField("product_sales")
    @Min(value=0)
    private Integer productSales;

    @ApiModelProperty(value = "库存")
    @TableField("product_stock")
    @NotNull(message = "库存不可为空",groups = AddGroup.class)
    @Min(value=0)
    private Integer productStock;

    @ApiModelProperty(value = "商品原价格")
    @TableField("product_old_price")
    @Min(value=0)
    private BigDecimal productOldPrice;

    @ApiModelProperty(value = "商品单价")
    @TableField("product_price")
    @NotNull(message = "商品单价不可为空",groups = AddGroup.class)
    @Min(value=0)
    private BigDecimal productPrice;

    @ApiModelProperty(value = "单位规格")
    @TableField("product_unit")
    @NotNull(message = "商品规格不可为空",groups = AddGroup.class)
    private String productUnit;

    @ApiModelProperty(value = "商品介绍")
    @TableField("product_detail")
    @NotNull(message = "商品介绍不可为空",groups = AddGroup.class)
    private String productDetail;

    @ApiModelProperty(value = "商品状态")
    @TableField("product_status")
    private Boolean productStatus;

    @ApiModelProperty(value = "商品版本号(乐观锁)")
    @TableField("product_version")
    @Null(message = "非法输入版本号",groups = AddGroup.class)
    @Version
    private Integer productVersion;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

}
